﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibEBML.Common;
namespace MKVSplitter
{
    class Program
    {
        static void Main(string[] args)
        {
            string Filename = @"f:\videos\[神のみぞ知るセカイ][op][God_only_knows_第三幕].mkv";
            //string Filename = @"F:\TDDOWNLOAD\Godonlyknows.mkv";
            using (var reader = System.IO.File.OpenRead(Filename))
            {
                using (var buffer = new System.IO.BufferedStream(reader))
                {
                    EBMLDocument document = new EBMLDocument(buffer);
                    Matroska mts = new Matroska(document);
                    Segment seg = mts.Segment;
                    var cs = seg.Clusters;
                    long l1 = 0;
                    //foreach (var item in cs)
                    var item = cs[0];
                    {
                        var bs = item.Blocks.Where(m => m.TrackNumber == 1);

                       // foreach (var item1 in bs)
                        var item1 = bs.FirstOrDefault();
                        {
                            var ds = item1.GetBlockData(null);
                            Console.WriteLine("Duration1={0},Duration2={1}", item.TimeCode + item1.TimeCode - l1, seg.Tracks[0].DefaultDuration / seg.Info.TimecodeScale);

                            if (item1 is Block)
                            {
                                var b = item1 as Block;

                                Console.WriteLine("{0}-{1}，ref{2}", item.TimeCode + b.TimeCode, item.TimeCode + b.TimeCode + b.BlockDuration,b.ReferenceBlock);
                            }
                            else
                            {

                            }
                            l1 = item.TimeCode + item1.TimeCode;
                        }
                    }
                }
                //string str = "FF00 0100 C05D0000 E02E0000 0400 1000 0500 130856E598";
                //string str2 = "FF00 0200 80BB0000 E02E0000 0400 1000 0200 1190";
                //string str3 = "FF00 0200 44AC0000 20620500 0400 1000 0200 1210";
                Console.ReadLine();
            }
        }
    }
}
